<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('分润日结明细列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 80px">品牌名称：</label>
                                <select name="manuNum" >
                                    <option value="">选择品牌</option>
                                    <option th:each="m:${manufacturer}" th:text="${m.MANU_NAME}" th:value="${m.MANU_NUM}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 80px;">交易流水号：</label>
                                <input type="text" name="serial"/>
                            </li>
                            <li>
                                <label style="width: 80px;">服务商编号：</label>
                                <input type="text" name="agentNo"/>
                            </li>
                            <li>
                                <label style="width: 80px;">商户编号：</label>
                                <input type="text" name="merno"/>
                            </li>
                            <li>
                                <label style="width: 80px;">终端SN：</label>
                                <input type="text" name="machineNum"/>
                            </li>
                            <li>
                                <label style="width: 80px;">档位代号：</label>
                                <input type="text" name="grade"/>
                            </li>
                            <li class="select-time">
                                <label style="width: 80px;">添加日期：</label>
                                <input type="text" readonly class="time-input" id="startTime" placeholder="开始日期" name="params[beginAddTime]"/>
                                <span>-</span>
                                <input type="text" readonly class="time-input" id="endTime" placeholder="结束日期" name="params[endAddTime]"/>
                            </li>
                            <li class="select-time">
                                <label style="width: 80px;">分润日期：</label>
                                <input type="text" readonly class="time-input"  placeholder="开始日期" name="startDate"/>
                                <span>-</span>
                                <input type="text" readonly class="time-input"  placeholder="结束日期" name="endDate"/>
                            </li>
                            <li>
                                <label style="width: 80px;">云闪付交易：</label>
                                <select name="isysf">
                                    <option value="">请选择</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 80px;">卡类型：</label>
                                <select name="cardtype">
                                    <option value="">所有</option>
                                    <option value="0">未知</option>
                                    <option value="1">借记卡</option>
                                    <option value="2">贷记卡</option>
                                    <option value="3">预付费卡</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 80px">分润类型：</label>
                                <select name="ptype" th:with="type=${@dict.getType('profit_type')}">
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 80px;">结算流水号：</label>
                                <input type="text" name="settleSerial"/>
                            </li>
                            <li>
                                <label style="width: 80px;">终端类型：</label>
                                <select name="posType" th:with="type=${@dict.getType('terminal_type')}">
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label style="width: 80px;">交易日期：</label>
                                <input type="text" readonly class="time-input"  placeholder="开始日期" name="params[beginTradeTime]"/>
                                <span>-</span>
                                <input type="text" readonly class="time-input"  placeholder="结束日期" name="params[endTradeTime]"/>
                            </li>
                            <li>
                                <label style="width: 80px;">是否统计：</label>
                                <select name="tong">
                                    <option value="1">否</option>
                                    <option value="0">是</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="mySearch()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                            <!--<li style="text-align: center"><span style="color: red;margin-top:7px;font-weight:bold;">【请输入条件,然后点击“搜索”按钮查询数据】</span></li>-->
                            <li>
                             <span style="color: blue;margin-top:7px;font-weight:bold;">
<!--                                 【交易总笔数:<span id="sunCount" style="color:red" th:text="${(trade.SUM_COUNT)}"></span>笔&nbsp;&nbsp;<span style="color:green">|</span>-->
<!--                                 交易总金额:<span id="amount" style="color:red" th:text="${(trade.AMOUNT)}"></span>元&nbsp;<span style="color:green">|</span>-->
<!--                                 商户手续费:<span id="tradeCharges" style="color:red" th:text="${(trade.TRADE_CHARGES)}"></span>元&nbsp;&nbsp;<span style="color:green">|</span>-->
<!--                                 直推分润总金额:<span id="oneProfitBerforTax" style="color:red" th:text="${(sumOneList.PROFIT_BERFORTAX)}"></span>元&nbsp;&nbsp;<span style="color:green">|</span>-->
<!--                                 直推分润税额:<span id="oneTaxMoney" style="color:red" th:text="${(sumOneList.TAX_MONEY)}"></span>元&nbsp;<span style="color:green">|</span>-->
<!--                                 直推分润税后金额:<span id="oneProfit" style="color:red"  th:text="${(sumOneList.PROFIT)}"></span>元&nbsp;&nbsp;<span style="color:green">|</span>-->
<!--                                 团队分润总金额:<span id="groupProfitBerforTax" style="color:red" th:text="${(sumGroupList.PROFIT_BERFORTAX)}"></span>元&nbsp;&nbsp;<span style="color:green">|</span>-->
<!--                                 团队分润总税额<span id="groupTaxMoney" style="color:red"  th:text="${(sumGroupList.TAX_MONEY)}"></span>&nbsp;&nbsp;<span style="color:green">|</span>-->
<!--                                 团队分润税后金额<span id="groupProfit" style="color:red"  th:text="${(sumGroupList.PROFIT)}"></span>元】</span>-->

                                【交易总笔数:<span id="sunCount" style="color:red" th:text="0"></span>笔&nbsp;&nbsp;<span style="color:green">|</span>
                                交易总金额:<span id="amount" style="color:red" th:text="0"></span>元&nbsp;<span style="color:green">|</span>
                                商户手续费:<span id="tradeCharges" style="color:red" th:text="0"></span>元&nbsp;&nbsp;<span style="color:green">|</span>
                                直推分润总金额:<span id="oneProfitBerforTax" style="color:red" th:text="0"></span>元&nbsp;&nbsp;<span style="color:green">|</span>
                                直推分润税额:<span id="oneTaxMoney" style="color:red" th:text="0"></span>元&nbsp;<span style="color:green">|</span>
                                直推分润税后金额:<span id="oneProfit" style="color:red"  th:text="0"></span>元&nbsp;&nbsp;<span style="color:green">|</span>
                                团队分润总金额:<span id="groupProfitBerforTax" style="color:red" th:text="0"></span>元&nbsp;&nbsp;<span style="color:green">|</span>
                                团队分润总税额:<span id="groupTaxMoney" style="color:red"  th:text="0"></span>&nbsp;&nbsp;<span style="color:green">|</span>
                                团队分润税后金额:<span id="groupProfit" style="color:red"  th:text="0"></span>元】</span>
                            </li>

                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="profitDay:detailed:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table text-nowrap"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "profitDay/detailed";
        var terminalTypeDatas = [[${@dict.getType('terminal_type')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "分润日结明细",
                firstLoad:false,
                columns: [
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'serial',
                    title: '交易流水号'
                },
                {
                    field: 'agentNo',
                    title: '服务商编号'
                },
                {
                    field: 'agentName',
                    title: '服务商名称'
                },
                {
                    field: 'merno',
                    title: '商户编号'
                },
                {
                    field: 'machineNum',
                    title: '终端SN'
                },
                {
                    field: 'posType',
                    title: '终端类型',
                    formatter:function(value,row,index){
                        return $.table.selectDictLabel(terminalTypeDatas, value);
                    }
                },
                {
                    field: 'cardtype',
                    title: '卡类型',
                    formatter: function (value, row, index) {
                        if ("0" == value) {
                            return '<span style="color:orange;">未知</span>';
                        } else if ("1" == value) {
                            return '<span style="color:green;">借记卡</span>';
                        } else if ("2" == value) {
                            return '<span style="color:red;">贷记卡</span>';
                        } else if ("3" == value) {
                            return '<span style="color:purple;">预付费卡</span>';
                        }
                    }
                },
                {
                    field: 'isysf',
                    title: '是否云闪付',
                    formatter: function (value, row, index) {
                        if (value == '0') {
                            return '<span style="color:red;">否</span>';
                        } else if (value == '1') {
                            return '<span style="color:green;">是</span>';
                        }
                    }
                },
                {
                    field: 'amount',
                    title: '交易金额',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
                {
                    field: 'profit',
                    title: '分润金额',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
                {
                    field: 'grade',
                    title: '档位代号',
                    formatter: function (value, row, index) {
                        if (value == '3') {
                            return "引流奖励"
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'gRate',
                    title: '分润比率(%)',
                    formatter: function (value, row, index) {
                        return value+"%";
                    }
                },
                {
                    field: 'addtime',
                    title: '添加时间'
                },
                {
                    field: 'createDate',
                    title: '分润日期'
                },
                {
                    field: 'localtime',
                    title: '交易时间',
                    formatter: function (value, row, index) {
                        return row.localdate + " " + value;
                    }
                },
                {
                    field: 'ptype',
                    title: '分润类型',
                    formatter:function(value,row,index){
                        if (value == '0'){
                            return "直推商户交易分润";
                        } else if (value == '1'){
                            return "团队分润";
                        }else if (value == '2') {
                            return "引流奖励";
                        }else if (value == '25') {
                            return "流量卡费分润";
                        }
                    }
                },
                {
                    field: 'settleSerial',
                    title: '结算流水号'
                },
                {
                    field: 'taxPoint',
                    title: '税点(%)',
                    formatter: function (value, row, index) {
                        return value+"%";
                    }
                },
                {
                    field: 'profitBerfortax',
                    title: '税前利润',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
                {
                    field: 'taxMoney',
                    title: '税金',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
               ]
            };
            $.table.init(options);
            layui.use('laydate', function() {
                var laydate = layui.laydate;

            });
        });
        function mySearch(formId, tableId, data) {
            table.set(tableId);
            var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
            var params = $.common.isEmpty(tableId) ? $("#" + table.options.id).bootstrapTable('getOptions') : $("#" + tableId).bootstrapTable('getOptions');
            params.queryParams = function(params) {
                var search = $.common.formToJSON(currentId);
                if($.common.isNotEmpty(data)){
                    $.each(data, function(key) {
                        search[key] = data[key];
                    });
                }
                search.pageSize = params.limit;
                search.pageNum = params.offset / params.limit + 1;
                search.searchValue = params.search;
                search.orderByColumn = params.sort;
                search.isAsc = params.order;
                return search;
            }
            if($.common.isNotEmpty(tableId)){
                $("#" + tableId).bootstrapTable('refresh', params);
            } else{
                $("#" + table.options.id).bootstrapTable('refresh', params);
            }

            if($.common.formToJSON('formId').tong == 1){
                totalRefresh($.common.formToJSON('formId'));
            }else{
                $('#oneProfitBerforTax').text(0.00);
                $('#oneTaxMoney').text(0.00);
                $('#oneProfit').text(0.00);
                $('#groupProfitBerforTax').text(0.00);
                $('#groupTaxMoney').text(0.00);
                $('#groupProfit').text(0.00);
                $('#sunCount').text(0.00);
                $('#amount').text(0.00);
                $('#tradeCharges').text(0.00);
            }
        }
        function totalRefresh(data) {
            $.ajax({
                url : prefix + "/totalRefresh",
                type: 'POST',
                data: data,
                dataType: "json",
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success : function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $('#oneProfitBerforTax').text(result.data.oneProfitBerforTax);
                        $('#oneTaxMoney').text(result.data.oneTaxMoney);
                        $('#oneProfit').text(result.data.oneProfit);
                        $('#groupProfitBerforTax').text(result.data.groupProfitBerforTax);
                        $('#groupTaxMoney').text(result.data.groupTaxMoney);
                        $('#groupProfit').text(result.data.groupProfit);
                        $('#sunCount').text(result.data.sunCount);
                        $('#amount').text(result.data.amount);
                        $('#tradeCharges').text(result.data.tradeCharges);
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    }  else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                    $.modal.enable();
                },
                error : function(result) {
                    $.modal.alertError(result.msg);
                }
            });

        }
    </script>
</body>
</html>
